var e = require;
var t = module;
var o,
    n = (o = e("Platform")) && o.__esModule ? o : {default: o};
cc.Class({
    extends: cc.Component,
    properties: {
        lToastPrefab: {default: null, type: cc.Prefab},
        blockTouchNode: cc.Node,
        subContextPrefab: cc.Prefab,
        lvCfg: cc.JsonAsset
    },
    onLoad: function onLoad() {
        (window.lGlobal = this),
            (cc.director.getPhysicsManager().enabled = !0),
            (cc.director.getCollisionManager().enabled = !0),
            cc.game.addPersistRootNode(this.node),
            (this.ltoastPool = new cc.NodePool()),
            this.loadUserData(),
            window.lplatform || (this.platform = new n.default()),
            (this.MODEL_CUSTOM = "Custom"),
            (this.MODEL_WORD_FIND = "WordFind"),
            (this.MODEL_LINE_CONNECT = "LineConnect"),
            (this.MODEL_PACK_MAN = "PackMan"),
            (this.MODEL_DRAG_CONNECT = "DragConnect"),
            (this.MODEL_DISJOINT_WORD = "DisjointWord"),
            (this.MODEL_DROP_DOWN_SELECT = "DropDownSelect"),
            (this.MODEL_RIDDLE_WORD = "RiddleWord"),
            (this.MODEL_RUSSIA_WORD = "RussiaWord"),
            (this.MODEL_WRONG_WORD_FIND = "WrongWordFind"),
            (this.MODEL_MOVIES = "Movies"),
            (this.MODEL_SONGS = "Songs"),
            (this.MODEL_BOOKS = "Books"),
            (this.MODEL_DIALECT = "Dialect"),
            (this.MODEL_CARTOON_COMIC_GAMES = "CartoonComicGames"),
            (this.MODEL_INTERNET_HOTSPOT = "InternetHotspot"),
            (this.MODEL_FOREIGN_LANGUAGE = "ForeignLanguage"),
            (this.model = null),
            (this.curModel = ""),
            (this.curLevel = 0),
            (this.realLevel = 0),
            (this.modelBundles = {}),
            (this.curWordBgColorIndex = 0),
            (this.wordBgColors = this.lvCfg.json.wordBgColors),
            (this.modelNames = this.lvCfg.json.modelNames);
    },
    start: function start() {
        this.hideBlockTouch(), (this.node.zIndex = cc.macro.MAX_ZINDEX);
    },
    getNextWordBgColor: function getNextWordBgColor() {
        var e = this.wordBgColors[this.curWordBgColorIndex];
        return (
            this.curWordBgColorIndex++,
            this.curWordBgColorIndex >= this.wordBgColors.length && (this.curWordBgColorIndex = 0),
            e
        );
    },
    loadUserData: function loadUserData() {
        var e = cc.sys.localStorage.getItem("userData");
        this.userData = null;
        var t = new Date(),
            o = t.getFullYear(),
            n = t.getMonth() + 1,
            i = t.getDate();
        e
            ? ((this.userData = JSON.parse(e)),
              this.userData.firstInDate &&
                  (this.userData.day =
                      365 * (o - this.userData.firstInDate[0]) +
                      31 * (n - this.userData.firstInDate[1]) +
                      i -
                      this.userData.firstInDate[2]))
            : (this.userData = {
                  score: 0,
                  firstInDate: [o, n, i],
                  day: 0,
                  level: 0,
                  modelLevel: {
                      Custom: 0,
                      WordFind: 0,
                      LineConnect: 0,
                      PackMan: 0,
                      DragConnect: 0,
                      DisjointWord: 0,
                      DropDownSelect: 0,
                      RiddleWord: 0,
                      RussiaWord: 0,
                      WrongWordFind: 0,
                      Movies: 0,
                      Songs: 0,
                      Books: 0,
                      Dialect: 0,
                      CartoonComicGames: 0,
                      InternetHotspot: 0,
                      ForeignLanguage: 0
                  },
                  levelState: {
                      Custom: [1],
                      WordFind: [1],
                      LineConnect: [1],
                      PackMan: [1],
                      DragConnect: [1],
                      DisjointWord: [1],
                      DropDownSelect: [1],
                      RiddleWord: [1],
                      RussiaWord: [1],
                      WrongWordFind: [1],
                      Movies: [1],
                      Songs: [1],
                      Books: [1],
                      Dialect: [1],
                      CartoonComicGames: [1],
                      InternetHotspot: [1],
                      ForeignLanguage: [1]
                  }
              });
    },
    saveUserData: function saveUserData() {
        cc.sys.localStorage.setItem("userData", JSON.stringify(this.userData));
    },
    loadLevel: function loadLevel(e, t) {
        var o = this;
        if (
            (void 0 === e ? (e = this.model) : (this.model = e),
            void 0 === t && console.err("loadLevel lv cannot be fucking undefined or null"),
            t >= this.lvCfg.json[e].length)
        )
            this.showLToast("敬请期待新关卡");
        else {
            var n = e,
                i = t;
            if (
                ((this.realLevel = t),
                "Custom" == e ||
                    "Movies" == e ||
                    "Songs" == e ||
                    "Books" == e ||
                    "Dialect" == e ||
                    "CartoonComicGames" == e ||
                    "InternetHotspot" == e ||
                    "ForeignLanguage" == e)
            ) {
                var a = this.lvCfg.json[e];
                (n = a[t].model), (i = a[t].modelIndex);
            }
            (this.curModel = n),
                (this.curLevel = i),
                this.loadSubPackage(
                    n,
                    function (e) {
                        (o.modelBundles[n] = e), cc.director.loadScene(n);
                    },
                    function () {
                        console.log("load bundle fail:" + e);
                    }
                );
        }
    },
    showLToast: function showLToast(e) {
        var t = null;
        ((t = this.ltoastPool.size() > 0 ? this.ltoastPool.get() : cc.instantiate(this.lToastPrefab)).group =
            "default"),
            (t.parent = cc.director.getScene().getChildByName("Canvas")),
            (t.active = !0),
            (t.zIndex = cc.macro.MAX_ZINDEX),
            t.getComponent("LToast").show(e);
    },
    convertPosToNode: function convertPosToNode(e, t, o) {
        var n = null;
        if (e)
            if ((t || (t = cc.find("Canvas")), o || (o = cc.v3(0, 0, 0)), e.parent == t)) n = e.position;
            else {
                var i = e.convertToWorldSpaceAR(o);
                n = t.convertToNodeSpaceAR(i);
            }
        return n;
    },
    getIndexFromParentsChildArray: function getIndexFromParentsChildArray(e) {
        var t = -1;
        if (e && e.parent)
            for (var o = 0; o < e.parent.children.length; o++) {
                if (e == e.parent.children[o]) {
                    t = o;
                    break;
                }
            }
        return t;
    },
    getNodeInCNode: function getNodeInCNode(e, t) {
        var o = null;
        if (e && t) {
            var n = t.convertToWorldSpaceAR(cc.v2(0, 0)),
                i = e.convertToWorldSpaceAR(cc.v2(0, 0)),
                a = i.x,
                r = i.y,
                s = n.x,
                d = n.y,
                c = t.width,
                l = t.height,
                h = Math.abs(s - a),
                u = Math.abs(d - r);
            h <= c / 2 && u <= l / 2 && (o = t);
        }
        return o;
    },
    blockTouch: function blockTouch() {
        this.blockTouchNode && (this.blockTouchNode.active = !0);
    },
    hideBlockTouch: function hideBlockTouch() {
        this.blockTouchNode && (this.blockTouchNode.active = !1);
    },
    getAniByName: function getAniByName(e) {
        for (var t = null, o = 0; o < this.moveTypes.length; o++) {
            if (this.moveTypes[o] && this.moveTypes[o].name === e) {
                t = this.moveTypes[o];
                break;
            }
        }
        return t;
    },
    initLockNode: function initLockNode() {
        var e = null;
        return this.lockPrefab && (e = cc.instantiate(this.lockPrefab)), e;
    },
    nodeShot: function nodeShot(e, t, o) {
        var n = new cc.Node();
        (n.width = e.width), (n.height = e.height), n.setParent(e);
        var i = n.addComponent(cc.Camera);
        if (
            ((cc.macro.ENABLE_TILEDMAP_CULLING = !1),
            (i.zoomRatio = 1),
            (i.clearFlags = cc.Camera.ClearFlags.DEPTH | cc.Camera.ClearFlags.STENCIL),
            (i.alignWithScreen = !1),
            (i.ortho = !0),
            (i.orthoSize = e.height / 2),
            (i.fov = e.width / 2),
            (i.depth = 0),
            o ||
                ((o = new cc.RenderTexture()),
                cc.game._renderContext,
                o.initWithSize(e.width, e.height, cc.gfx.RB_FMT_S8)),
            (i.targetTexture = o),
            t)
        )
            for (var a = 0; a < t.length; a++) {
                t[a] && ((i.cullingMask = t[a]._cullingMask), i.render(t[a]));
            }
        return (cc.macro.ENABLE_TILEDMAP_CULLING = !0), e.removeChild(n), o;
    },
    loadScene: function loadScene(e) {
        var t = null;
        return (
            this.blockTouchNode.active ||
                (this.blockTouch(),
                (this.blockTouchNode.opacity = 0),
                cc
                    .tween(this.blockTouchNode)
                    .to(0.3, {opacity: 255})
                    .call(
                        function () {
                            cc.director.loadScene(e),
                                "huaWei" != lplatform.channel || window.huaWeiYinSiAgree,
                                (this.blockTouchNode.opacity = 255),
                                cc
                                    .tween(this.blockTouchNode)
                                    .to(0.3, {opacity: 0})
                                    .call(
                                        function () {
                                            this.hideBlockTouch();
                                        }.bind(this)
                                    )
                                    .start();
                        }.bind(this)
                    )
                    .start(),
                (t = cc.director.preloadScene(e, function () {}.bind(this), function () {}.bind(this)))),
            t
        );
    },
    loadSubPackage: function loadSubPackage(e, t, o) {
        return (
            cc.assetManager.loadBundle(e, null, function (e, n) {
                e ? o && o() : t && t(n);
            }),
            null
        );
    }
});
